const { ipcrender, contextBridge, ipcRenderer } = require("electron");

window.addEventListener("DOMContentLoaded", () => {
  // console.log("preload", process.versions);
});

contextBridge.exposeInMainWorld("electronAPI", {
  getVersions: (callback) => {
    ipcRenderer.send("sendToMain");
    ipcRenderer.on("sendToRenderer", (event, value) => {
      callback(value);
    });
  },
  menuEvent: (callback) => {
    ipcRenderer.on("toPreload", (event, value) => {
      console.log("preload", value);
      callback(value);
    });
  },
  getValues: (callback) => {},
  selectFilePreload: () => {
    return ipcRenderer.invoke("selectFileMain");
  },
  saveToFile: (value) => {
    ipcRenderer.send("saveFileMain", value);
  },
});

window.addEventListener("contextmenu", () => {
  console.log("contextmenu");
  ipcRenderer.send("mainPopMenu");
});
// 接收到菜单发过来的value
// ipcRenderer.on("toPreload", (event, value) => {
//   console.log("toPreload", value);
// });
